{extend name="index_layout"/}
{block name="main"}
<div class="layui-card">
    <div class="layui-card-header">用户管理</div>
    <div class="layui-card-body">
        <div class="layui-form">
            <table class="layui-hide" id="currentTable" lay-filter="currentTable"></table>
        </div>
    </div>

</div>

<script type="text/html" id="card1">
    {{#  if(d.card1){ }}
    <div><a href="{{d.card1}}" target="_blank"><img style='width: 40%;height: 100%' src='{{d.card1}}' alt=''></a></div>
    {{#  } }}
</script>

<script type="text/html" id="barTool">
    <a data-open='{:url("edit")}?id={{ d.id }}'
       class="layui-btn layui-btn-xs {:$auth->check('user/edit')?'':'layui-hide'}" title="编辑">绑定主播ID</a>
</script>

<script type="text/html" id="card2">
    {{#  if(d.card2){ }}
    <div><a href="{{d.card2}}" target="_blank"><img style='width: 40%;height: 100%' src='{{d.card2}}' alt=''></a></div>

    {{#  } }}
</script>


<!--<script type="text/html" id="barTool">-->

<!--   -->
<!--</script>-->

{/block}
{block name="script"}
<script type="text/javascript">
    layui.use(['yznTable', 'yznUpload'], function () {
        var table = layui.yznTable;

        var yznUpload = layui.yznUpload;


        var init = {
            table_elem: '#currentTable',
            table_render_id: 'currentTable',
            modify_url: '{:url("multi")}',

        };

        table.render({
            init: init,
            toolbar: ['refresh'],
            url: '{:url("index")}',
            cols: yznTable.formatCols([
                [
                    {field: 'id', width: 80, title: 'ID'},
                    {
                        width: 100,
                        title: '头像',
                        align: 'center',
                        templet: "<div><img style='width: 40%;height: 100%' src='{{d.avatar}}' alt=''></div>",
                    },
                    {field: 'nickname', align: 'center', title: '昵称', searchOp: 'like'},
                    {field: 'openid', title: 'openid', search: false},
                    {field: 'zhu_id', title: '主播ID'},


                    {
                        field: 'type',
                        align: 'center',
                        width: 120,
                        title: '是否为主播',
                        unresize: true,
                        templet: yznTable.formatter.switch,
                        selectList: {0: '否', 1: '是'},
                        tips: "是|否"
                    },


                    {
                        field: 'status',
                        align: 'center',
                        width: 120,

                        title: '状态',
                        unresize: true,
                        templet: yznTable.formatter.switch,

                        selectList: {1: '正常', 0: '冻结'},
                        tips: "正常|冻结"
                    },
                    {field: 'create_time', align: 'center', title: '创建时间', search: 'range'},
                    {fixed: 'right', align: 'center', width: 140, title: '操作', toolbar: '#barTool'}
                ]
            ], init),
            page: {},
            done: function (res, curr, count) {
                yznUpload.api.upload('.faupload', function (data, ret) {
                    var path = data.path;
                    var id = $(this).data("id")
                    if (path) {
                        yzn.request.post({
                            url: '{:url("user/import")}',
                            data: {
                                id: id,
                                path: path
                            }
                        }, function (data, res) {
                            layer.close(index);
                            yzn.msg.success(res.msg);
                        });
                    } else {
                        yzn.msg.success('上传失败');
                    }

                });
            }
        });
        yznTable.listenSwitch({filter: 'status', url: init.modify_url});
        yznTable.listenSwitch({filter: 'type', url: init.modify_url});

        yznTable.bindevent();
    });
</script>
{/block}